<!DOCTYPE html>
<html>
<title>魔盒配置</title>
<head>
    <link href="/css/layui/css/layui.css" rel="stylesheet">
    <link href="/css/hadmin/css/bootstrap.min.css" rel="stylesheet">
    <link href="/css/bootstrap-datetimepicker.min.css" rel="stylesheet">
    <link href="/css/hadmin/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="/css/hadmin/css/animate.css" rel="stylesheet">
    <link href="/css/hadmin/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="/css/hadmin/css/animate.css" rel="stylesheet">
    <link href="/css/bootstrap-select.min.css" rel="stylesheet">
    <link href="/css/multi-select.dist.css" rel="stylesheet">
</head>

<div class="wrapper wrapper-content animated fadeInUp">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox">
                <div class="ibox-title">
                    <h5>魔盒配置</h5>
                </div>
                <div class="ibox-content">
                    <form class="form-inline">
                        <div class="form-group">
                            <select name="nextBoxRate" id="nextBoxRate" class="form-control selectpicker"
                                    data-live-search="true" data-size="8">
                                <?php foreach($params['props'] as $prid => $val): ?>
                                <option value="<?=$prid?>">-&nbsp;<?=$val?></option>
                                <?php endforeach; ?>
                            </select>
                        </div>

                        <div class="form-group" style="margin-left: 20px">
                            <div class="input-group">
                                <span class="input-group-btn">
                                <button type="button" class="btn btn-info submitNew">添加礼物</button>
                                </span>
                            </div>
                        </div>
                    </form>

                    <div style="display: inline-flex;height: 400px;flex-direction: column;flex-wrap: wrap;">
                        <?php foreach($params['prop'] as $v): ?>
                        <div class="form-inline" style="width: 600px">
                            <div style="margin: 20px;width: 600px">
                                <div class="form-group">
                                    <label><?= $v['prop_name'] ?></label>
                                    <div class="input-group">
                                        <span class="input-group-addon">中奖概率%</span>
                                        <input type="text" class="form-control rate" data-id="<?= $v['id']?>"
                                               value="<?= $v['rate'] ?>">
                                    </div>
                                </div>
                                <button type="submit" class="btn btn-default resetRate">修改</button>
                                <button type="button" class="btn btn-default dellRate">删除</button>
                                <br/>
                            </div>
                        </div>
                        <?php endforeach;?>
                    </div>
                    <?php foreach($params['coin'] as $v): ?>
                    <div class="form-inline" style="width: 600px">
                        <div style="margin: 20px;width: 600px">
                            <div class="form-group">
                                <label><?=$v['prid']?>金币</label>
                                <div class="input-group">
                                    <span class="input-group-addon">中奖概率%</span>
                                    <input type="text" class="form-control rate" data-id="<?= $v['id']?>"
                                           value="<?= $v['rate'] ?>">
                                </div>
                            </div>
                            <button type="submit" class="btn btn-default resetRate">修改</button>
                            <button type="button" class="btn btn-default dellRate">删除</button>
                            <br/>
                        </div>
                    </div>
                    <?php endforeach;?>
                </div>

                <div class="panel panel-default">
                    <div class="panel-heading"><b>魔盒产出配置</b></div>
                    <div style="display: flex; flex-direction: row">
                        <div  class="form-inline">
                            <div style="margin: 20px">
                                <div class="form-group">
                                    <label>参与盲盒交友产出魔盒</label>
                                    <div class="input-group">
                                        <span class="input-group-addon">中奖概率%</span>
                                        <input type="text" class="form-control" data-id="blidbox_getmagicbox"  value="<?= $params['magicGetRate']['blidbox_getmagicbox'] ?>" >
                                    </div>
                                </div>
                                <button type="submit" class="btn btn-default resetRate1">修改</button>
                                <br />
                            </div>

                            <div style="margin: 20px">
                                <div class="form-group">
                                    <label>每天首次登录产出魔盒</label>
                                    <div class="input-group">
                                        <span class="input-group-addon">中奖概率%</span>
                                        <input type="text" class="form-control" data-id="login_getmagicbox"  value="<?= $params['magicGetRate']['login_getmagicbox'] ?>" >
                                    </div>
                                </div>
                                <button type="submit" class="btn btn-default resetRate1">修改</button>
                                <br />
                            </div>

                            <div style="margin: 20px">
                                <div class="form-group">
                                    <label>每日签到产出魔盒</label>
                                    <div class="input-group">
                                        <span class="input-group-addon">中奖概率%</span>
                                        <input type="text" class="form-control" data-id="signin_getmagicbox"  value="<?= $params['magicGetRate']['signin_getmagicbox'] ?>" >
                                    </div>
                                </div>
                                <button type="submit" class="btn btn-default resetRate1">修改</button>
                                <br />
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>
</html>

<script src="/css/layui/layui.js"></script>
<script src="/css/hadmin/js/jquery.min.js?v=2.1.4"></script>
<script src="/css/hadmin/js/bootstrap.min.js?v=3.3.6"></script>
<script src="/css/hadmin/js/plugins/metisMenu/jquery.metisMenu.js"></script>
<script src="/css/hadmin/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script src="/css/hadmin/js/plugins/layer/layer.min.js"></script>
<script src="/css/hadmin/js//hAdmin.js?v=4.1.0"></script>
<script src="/css/hadmin/js/index.js"></script>
<script src="/js/moment-with-locales.min.js"></script>
<script src="/js/bootstrap-datetimepicker.min.js"></script>
<script src="/css/hadmin/js/plugins/toastr/toastr.min.js"></script>
<script src="/js/bootstrap-select.min.js"></script>
<script src="/js/jquery.multi-select.js"></script>

<script type="text/javascript">
    (function () {
        $(".submitNew").on('click', function () {
            $(this).blur();
            $(this).attr('disabled', 'disabled');
            let prop_id = $("#nextBoxRate").val();
            if (!prop_id) {
                layer.msg("缺少参数", {time: 2000, icon: 2}, () => {
                    window.location.reload();
                });
                return;
            }

            $.post('/platform/addNextBoxRate', {'prop_id': prop_id}, function (response) {
                if (response.code == 200) {
                    layer.msg(response.msg, {time: 2000, icon: 1}, () => {
                        window.location.reload();
                    });
                    return;
                }
                layer.msg(response.msg, {time: 2000, icon: 1}, () => {
                    window.location.reload();
                });
            }, 'json')
        })

        $(".dellRate").on('click', function () {
            $(this).blur();
            $(this).attr('disabled', 'disabled');
            let id = $(this).siblings('div').find('input').data('id');
            if (!id) {
                layer.msg("缺少参数", {time: 2000, icon: 2}, () => {
                    window.location.reload();
                });
                return;
            }
            $.post('/platform/dropNextBoxRate', {'id': id}, function (response) {
                if (response.code == 200) {
                    layer.msg(response.msg, {time: 2000, icon: 1}, () => {
                        window.location.reload();
                    });
                    return;
                }
                layer.msg(response.msg, {time: 2000, icon: 2}, () => {
                    window.location.reload();
                });
            }, 'json')
        })

        $(".resetRate").on('click', function () {
            $(this).blur();
            var id = $(this).siblings('div').find('input').data('id');
            var rate = $(this).siblings('div').find('input').val();
            var rates = 0;
            $('.rate').each(function () {
                rates = rates + parseInt($(this).val());
            });
            // $(this).attr('disabled','disabled');
            if (!id || !rate) {
                layer.msg('缺少参数', {time: 2000, icon: 2});
                return;
            }
            if (rate <= 0) {
                layer.msg('概率不能小于0', {time: 2000, icon: 2});
                return;
            }
            if (rates > 100) {
                layer.msg('概率之和不能大于100%', {time: 2000, icon: 2});
                return;
            }
            $.post('/platform/dellNextBox', {'id': id, 'rate': rate}, function (response) {
                if (response.code == 200) {
                    layer.msg(response.msg, {time: 2000, icon: 1}, () => {
                        window.location.reload();
                    });
                    return;
                }
                layer.msg(response.msg, {time: 2000, icon: 2}, () => {
                    window.location.reload();
                });
            }, 'json')
        })

        $(".resetRate1").on('click', function () {
            $(this).blur();
            var rate = $(this).siblings('div').find('input').val();
            var action = $(this).siblings('div').find('input').data('id');
            $(this).attr('disabled', 'disabled');
            if (!action || !rate) {
                layer.msg('缺少参数', {time: 2000, icon: 2});
                return;
            }
            if (rate <= 0) {
                layer.msg('不能小于0', {time: 2000, icon: 2});
                return;
            }
            if (rate > 100) {
                layer.msg('概率不能大于100', {time: 2000, icon: 2});
                return;
            }
            $.post('/platform/dellGetNextBox', {'rate': rate, 'action': action}, function (response) {
                if (response.code == 200) {
                    layer.msg(response.msg, {time: 2000, icon: 1}, () => {
                        window.location.reload();
                    });
                    return
                }
                layer.msg(response.msg, {time: 2000, icon: 2}, () => {
                    window.location.reload();
                });
            }, 'json')
        })
    })()
</script>